package cqrtplm.controller;

import com.hustcad.plm.pdm.classification.service.TyplmClassificationCacheService;
import com.hustcad.plm.pdm.enumeration.model.dto.HandleEnumItemDTO;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.dto.AttributeAndClassificationDTO;
import cqrtplm.dto.DescribeSpliceRuleDTO;
import cqrtplm.dto.DescriptionRuleDTO;
import cqrtplm.dto.RTClassifyTreeDTO;
import cqrtplm.dto.RTProductDevelopmentOrderDTO;
import cqrtplm.entity.DescribeSpliceRuleDO;
import cqrtplm.service.RTClassificationService;
import cqrtplm.vo.DescriptionRuleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;


@RestController
@Api(tags = "分类")
@RequestMapping(RouteConstant.CLASSIFICATION + "v1")
public class RTClassificationController {

    @Resource
    private RTClassificationService classificationService;

    @Resource
    private TyplmClassificationCacheService typlmClassificationCacheService;

    @PutMapping("/updateClassifyTree")
    @ApiOperation(value = "修改分类树", produces = "application/json; charset=utf-8")
    public ResponseResult<T> updateClassifyTree(@RequestBody RTClassifyTreeDTO rtClassifyTreeDTO) {
        classificationService.updateClassifyTree(rtClassifyTreeDTO);
        return ResponseResult.success();
    }

    @PostMapping("/queryProjectDetailByOid")
    @ApiOperation(value = "查询产品数据基础信息", produces = "application/json; charset=utf-8")
    public ResponseResult<RTProductDevelopmentOrderDTO> queryDetailByOid(@RequestBody RTProductDevelopmentOrderDTO rtProductDevelopmentOrderDTO) {
        return classificationService.queryProjectDetailByOid(rtProductDevelopmentOrderDTO);
    }

    @PostMapping("/insertDevelopmentOrder")
    @ApiOperation(value = "维护开发令", produces = "application/json; charset=utf-8")
    public ResponseResult<String> insertDevelopmentOrder(@RequestBody RTProductDevelopmentOrderDTO rtProductDevelopmentOrderDTO) {
        return ResponseResult.success(classificationService.addDevelopmentOrder(rtProductDevelopmentOrderDTO));
    }

    @RequestMapping("/updateAttributeByClassification")
    @ApiOperation(value = "同步属性", produces = "application/json; charset=utf-8")
    public ResponseResult updateAttributeByClassification(@RequestBody AttributeAndClassificationDTO dto){
        classificationService.updateAttributeByClassification(dto);
        return ResponseResult.success();
    }

    @RequestMapping("/saveAttrDescribeRule")
    @ApiOperation(value = "保存分类描述属性规则", produces = "application/json; charset=utf-8")
    public void saveAttrDescribeRule(@RequestBody DescribeSpliceRuleDTO describeTheSplicingRulesDO){
    	classificationService.saveAttrDescribeRule(describeTheSplicingRulesDO);
    }

    @PostMapping("/queryAttrDescribeRule")
    @ApiOperation(value = "根据分类查询描述属性规则", produces = "application/json; charset=utf-8")
    public ResponseResult<DescribeSpliceRuleDO> queryAttrDescribeRule(@RequestBody IdentifierEntity entity){
        return ResponseResult.success(classificationService.queryAttrDescribeRule(entity));
    }

    @RequestMapping("/spliceDescriptionRules")
    @ApiOperation(value = "拼接描述规则", produces = "application/json; charset=utf-8")
    public ResponseResult<DescriptionRuleVO> spliceDescriptionRules(@RequestBody List<DescriptionRuleDTO> list){
        DescriptionRuleVO vo = classificationService.spliceDescriptionRules(list);
        return ResponseResult.success(vo);
    }

    @GetMapping("/queryAllProductLine")
    @ApiOperation(value = "查询所有产品线", produces = "application/json; charset=utf-8")
    public ResponseResult<List<String>> queryAllProductLine(@RequestParam("parentoid") BigInteger parentoid){
        return ResponseResult.success(classificationService.queryAllProductLine(parentoid));
    }

    @GetMapping("/classificationOperator")
    @ApiOperation(value = "分类卡片操作", produces = "application/json; charset=utf-8")
    public ResponseResult<T> classificationOperator(@RequestParam("classificationOid") BigInteger classificationOid,
                                                    @RequestParam("type") String type) {
        classificationService.classificationOperator(classificationOid, type);
        return ResponseResult.success();
    }

    @PostMapping("/checkEnumByClassId")
    public ResponseResult<T> checkEnumByClassId(@RequestBody HandleEnumItemDTO handleEnumItemDTO) {
        classificationService.checkEnumByClassId(handleEnumItemDTO);
        return ResponseResult.success();
    }

    @PostMapping("/queryClassificationAll")
    public ResponseResult<T> queryClassificationAll() {
        return ResponseResult.success(typlmClassificationCacheService.queryClassificationAll());
    }

}
